﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace StorageBox
{
    public class ContextMenuManager : ManagerBase
    {
        private static ContextMenuManager _contextMenuManager;

        Dictionary<string, ContextMenu> _contextMenus = new();
        private MainWindow _mainWindow = BoxApplication.GetMainWondw();

        public ContextMenuManager()
        { }

        public ContextMenu CreateMenuByMainWindow()
        {
            _contextMenuManager = this;

            ContextMenu contextMenu = new();

            var item01 = CreateMenuItem(contextMenu, "开始菜单批量导入");
            item01.Click += _mainWindow.AddRangStateMenu_Click;

            _contextMenus["MainWindow"] = contextMenu;
            return contextMenu;
        }

        private MenuItem CreateMenuItem(ContextMenu menu, string name)
        {
            MenuItem menuItem = new();
            menuItem.Header = name;
            menuItem.FontSize = 12;
            menuItem.Height = 24;

            TextBlock textBlock = new() { FontSize = 12 };
            var curWidth = SY_Library.Text.GetDisPlayWidth(name, textBlock.FontFamily, textBlock.FontStyle, textBlock.FontWeight, textBlock.FontStretch, 12);
            menu.Width = (curWidth + 50 > menu.ActualWidth ? curWidth + 50 : menu.ActualWidth);

            menu.Items.Add(menuItem);
            return menuItem;
        }
    }
}
